package com.goddess.yeecolor.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.goddess.yeecolor.Modle.activity;
import com.goddess.yeecolor.R;
import com.goddess.yeecolor.interfaceAll.OnClickListener;
import com.goddess.yeecolor.tools.ImageUtils;

import java.util.List;

/**
 * 活动须知
 */
public class activityDetailsAdapter extends RecyclerView.Adapter<activityDetailsAdapter.ViewHoldes>{
    private OnClickListener mOnClick;
    private Context context;
    private List<activity> modleList;
    private int tag;
    public activityDetailsAdapter(List<activity> modleList,Context context,int tag){
        this.modleList=modleList;
        this.context=context;
        this.tag=tag;
    }

    @Override
    public ViewHoldes onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.fragment_activity_details,parent,false);
        ViewHoldes viewHoldes=new ViewHoldes(view);
        return viewHoldes;
    }

    @Override
    public void onBindViewHolder(ViewHoldes holder, int position) {
        activity activity=modleList.get(position);

            holder.activity_content.setText(activity.getText());


        if (!activity.getType().equals("title")){
            if (activity.getImage()!=null) {
                holder.activity_detailsImage.setVisibility(View.VISIBLE);
                ImageUtils.getInstance().ImageStart(context, activity.getImage(), holder.activity_detailsImage);
            }
            else {
                holder.activity_detailsImage.setVisibility(View.GONE);
            }
        }
        else {
            holder.activity_detailsImage.setVisibility(View.GONE);
        }


    }

    @Override
    public int getItemCount() {
        return modleList.size();
    }

    class ViewHoldes extends RecyclerView.ViewHolder{
        private ImageView activity_detailsImage;
        private TextView activity_content;
        public ViewHoldes(View itemView) {
            super(itemView);
            activity_content= (TextView) itemView.findViewById(R.id.activity_content);
            activity_detailsImage= (ImageView) itemView.findViewById(R.id.activity_detailsImage);
            itemView.setOnClickListener((view)->{
                mOnClick.OnClick(view,getLayoutPosition());
            });
        }
    }
    public void setOnClickListener(OnClickListener onClickListener){
        this.mOnClick=onClickListener;
    }
}
